package kz.pdt12.hw.data;

/**
 * Created with IntelliJ IDEA.
 * User: raimbek
 * Date: 07.03.13
 * Time: 1:20
 */
public class ContactData implements Comparable<ContactData>{
    public String id;
    public String firstName;
    public String lastName;
    public String address;
    public String telephoneHome;
    public String telephoneMobile;
    public String telephoneWork;

    public String email;

    public String email2;
    public String birthdayDay;
    public String birthdayMonth;
    public String birthdayYear;
    public String group;
    public String secondaryAddress;
    public String secondaryHomePhone;
    public ContactData() {
    }

    public ContactData(String firstName,
                       String lastName,
                       String address,
                       String telephoneHome,
                       String telephoneMobile,
                       String telephoneWork,
                       String email,
                       String email2,
                       String birthdayDay,
                       String birthdayMonth,
                       String birthdayYear,
                       String group,
                       String secondaryAddress,
                       String secondaryHomePhone) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
        this.telephoneHome = telephoneHome;
        this.telephoneMobile = telephoneMobile;
        this.telephoneWork = telephoneWork;
        this.email = email;
        this.email2 = email2;
        this.birthdayDay = birthdayDay;
        this.birthdayMonth = birthdayMonth;
        this.birthdayYear = birthdayYear;
        this.group = group;
        this.secondaryAddress = secondaryAddress;
        this.secondaryHomePhone = secondaryHomePhone;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTelephoneHome() {
        return telephoneHome;
    }

    public void setTelephoneHome(String telephoneHome) {
        this.telephoneHome = telephoneHome;
    }

    public String getTelephoneMobile() {
        return telephoneMobile;
    }

    public void setTelephoneMobile(String telephoneMobile) {
        this.telephoneMobile = telephoneMobile;
    }

    public String getTelephoneWork() {
        return telephoneWork;
    }

    public void setTelephoneWork(String telephoneWork) {
        this.telephoneWork = telephoneWork;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmail2() {
        return email2;
    }

    public void setEmail2(String email2) {
        this.email2 = email2;
    }

    public String getBirthdayDay() {
        return birthdayDay;
    }

    public void setBirthdayDay(String birthdayDay) {
        this.birthdayDay = birthdayDay;
    }

    public String getBirthdayMonth() {
        return birthdayMonth;
    }

    public void setBirthdayMonth(String birthdayMonth) {
        this.birthdayMonth = birthdayMonth;
    }

    public String getBirthdayYear() {
        return birthdayYear;
    }

    public void setBirthdayYear(String birthdayYear) {
        this.birthdayYear = birthdayYear;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String getSecondaryAddress() {
        return secondaryAddress;
    }

    public void setSecondaryAddress(String secondaryAddress) {
        this.secondaryAddress = secondaryAddress;
    }

    public String getSecondaryHomePhone() {
        return secondaryHomePhone;
    }

    public void setSecondaryHomePhone(String secondaryHome) {
        this.secondaryHomePhone = secondaryHome;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null) {
            return false;
        }
        if (getClass() != o.getClass()) {
            return false;
        }

        ContactData other = (ContactData) o;
        if (lastName == null) {
            if (other.getLastName() != null) {
                return false;
            }
        } else if (firstName == null) {
            if (other.getFirstName() != null) {
                return false;
            }
        }

        if (lastName.equals(other.getLastName())  && firstName.equals(other.getFirstName())) {
            return true;
        }
        return false;
    }


    @Override
    public int compareTo(ContactData otherContact) {
        lastName = (lastName == null)? "" : lastName.toLowerCase();
        firstName = (firstName == null)? "" : firstName.toLowerCase();

        String otherLastName = (otherContact.getLastName() == null)? "" : otherContact.getLastName().toLowerCase();
        String otherFirstName = (otherContact.getFirstName() == null)? "" : otherContact.getFirstName().toLowerCase();

        if (lastName.equals(otherLastName)) {
            return firstName.compareTo(otherFirstName);
        }
        return lastName.compareTo(otherLastName);
    }

    @Override
    public String toString() {
        return "ContactData [lastname=" + lastName + "] [firstname=" + firstName + "] \n" +
                "[telephoneHome=" + telephoneHome + "] \n";
    }

    public ContactData withFirstName(String firstName) {
        this.firstName = firstName;
        return this;
    }

    public ContactData withLastName(String lastName) {
        this.lastName = lastName;
        return this;
    }

    public ContactData withAddress(String address) {
        this.address = address;
        return this;
    }

    public ContactData withTelephoneHome(String telephoneHome) {
        this.telephoneHome = telephoneHome;
        return this;
    }

    public ContactData withTelephoneWork(String telephoneWork) {
        this.telephoneWork = telephoneWork;
        return this;
    }

    public ContactData withTelephoneMobile(String telephoneMobile) {
        this.telephoneMobile = telephoneMobile;
        return this;
    }

    public ContactData withEmail(String email) {
        this.email = email;
        return this;
    }

    public ContactData withEmail2(String email2) {
        this.email2 = email2;
        return this;
    }

    public ContactData withBirthdayDay(String birthdayDay) {
        this.birthdayDay = birthdayDay;
        return this;
    }

    public ContactData withBirthdayMonth(String birthdayMonth) {
        this.birthdayMonth = birthdayMonth;
        return this;
    }

    public ContactData withBirthdayYear(String birthdayYear) {
        this.birthdayYear = birthdayYear;
        return this;
    }

    public ContactData withSecondaryAddress(String secondaryAddress) {
        this.secondaryAddress = secondaryAddress;
        return this;
    }

    public ContactData withSecondaryHomePhone(String secondaryHomePhone) {
        this.secondaryHomePhone = secondaryHomePhone;
        return this;
    }
}
